package com.atde._05_behavioral_design_patterns.iterator;


import java.util.Iterator;

/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.iterator
 * @Author: Del
 * @CreateTime: 2025-06-27  15:05
 * @Description: 迭代器模式：需要遍历的集合对象，创建一个迭代器对象，从集合对象中获取数据，并且可以检测到集合对象的数据变化
 * @Version: 1.0
 */
public class ComputerCollege implements Colleage{

    private Department[] departments;

    public ComputerCollege() {
        departments = new Department[5];
        addDepartment("PHP", "PHP课程");
        addDepartment("C++", "C++课程");
        addDepartment("Python", "Python课程");
    }

    // 保存集合中添加的部门个数，size()方法可以获取
    private int numOfDepartment = 0;

    @Override
    public String getName() {
        return "计算机学院";
    }

    @Override
    public void addDepartment(String name, String desc) {
        Department department = new Department(name, desc);
        departments[numOfDepartment] = department;
        numOfDepartment += 1;
    }

    @Override
    public Iterator createIterator() {
        return new ComputerCollegeIterator(departments);
    }
}
